<?php

include_once('cfg/cfg.php');
include_once('lib/mysql.class.php');

class DB
{
	private static $db = null;
		
	public static function i()
	{
		global $dburl, $def_encoding;
		self::Log("dburl=$dburl");
		
		if(is_null(self::$db))
		{
			MySQL::$url = $dburl;
			MySQL::$encoding = $def_encoding;
			self::$db = MySQL::getInstance();
		}
		return self::$db;
	}

	private static function Log($msg)
	{ 
		$ymd = date("Y-m-d", mktime());
		$fd = fopen("logs/db.".$ymd.".log", "a+");
		$str  = date("H:i:s", mktime());
		$str .= "\t".$_SERVER['REMOTE_ADDR'];
		$str .= "\tdb.class.php\t".$msg."\n";
		fwrite($fd, $str);
		fclose($fd);
	}
}